<template>
  <div id="app">
      <el-upload
        class="avatar-uploader"
        action="https://jsonplaceholder.typicode.com/posts/"
        :show-file-list="false"
        :on-progress="startProcess"
        :on-success="handleAvatarSuccess"
        :before-upload="beforeAvatarUpload">
        <img v-if="success" src="@/assets/exc.jpg" class="avatar">
        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
        <el-progress v-if=processShow :percentage="process"></el-progress>
  </div>
</template>

<script>
export default {
    data(){
        return {
            success: false,
            processShow: false,
            process:0
        }
    },
    methods: {
        handleAvatarSuccess(){
            this.success = true
            this.process = 100
        },
        startProcess(event,file,fileList){
            this.processShow = true
            this.process = parseFloat(file.percentage.toFixed(0))
            console.log('看一下file文件',file);
        },
        beforeAvatarUpload(){}
    }
}
</script>

<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>